package org.techmore.hakka;

import org.techmore.common.utils.database.InitailDatabase;
import org.techmore.common.utils.sound.SoundPoolUtils;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class WelcomeActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setScreenOrientation();
        
        setContentView(R.layout.welcome_log);
        
        //初始化数据库
        InitailDatabase.getInstance().initDB(this);
        
        //初始化声音Utils
        SoundPoolUtils.getInstance(this);
        
        //初始化版本
        TextView hakka_version = (TextView) this.findViewById(R.id.hakka_version);
        initVersion(hakka_version);
        
        
        //两秒后跳转
        Handler handler = new Handler(Looper.myLooper());
        handler.postDelayed(new Runnable() {
			@Override
			public void run() {
				WelcomeActivity.this.startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
				overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
			}
		},2000);
        
    }
    
    
    //全屏
    private void setScreenOrientation(){
    	Window window = getWindow();
		window.requestFeature(Window.FEATURE_NO_TITLE);
		window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);	//豎屏
//    	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);		//橫屏
    }
    
   
    
    
    //初始化版本，从mainfest里面读
    private void initVersion(TextView welcome_version) {
		try {
			PackageInfo packageInfo = getPackageManager().getPackageInfo("org.techmore.hakka", PackageManager.GET_CONFIGURATIONS);
			welcome_version.setText(packageInfo.versionName);
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}